
const express = require('express')
const router = express.Router()
const db = require('../db/index')

// 获取根据商品id轮播图 
// http://127.0.0.1:3006/shop/getShopCarousel?id=1
router.get('/getShopCarousel', (req, res) => {
    if (!req.query.id) res.lose('参数错误')
    const id = Number(req.query.id)
    const sql = 'select * from shopdetailimg where shop_id = ?'
    db.query(sql, id, (err, result) => {
        if (err) return res.lose(err)
        res.send({
            message: '获取商品轮播图成功！',
            success: true,
            status: 0,
            result
        })
    })
})

// 获取根据id商品信息
router.get('/getShopInfo', (req, res) => {
    const id = Number(req.query.id)
    const sql = 'select * from hotshop where id = ?'
    db.query(sql, id, (err, result) => {
        if (err) return res.lose(err)
        res.send({
            message: '获取商品数据成功！',
            success: true,
            status: 0,
            result
        })
    })
})
module.exports = router;